package reduce.fz.com.reduce.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import org.w3c.dom.Text;

import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.adapter.BaseListAdapter;
import reduce.fz.com.reduce.adapter.BaseRecycleViewHolder;
import reduce.fz.com.reduce.bean.ArtistCard;
import reduce.fz.com.reduce.fragment.base.BaseGridFragment;
import reduce.fz.com.reduce.util.PicassoUtil;
import reduce.fz.com.reduce.util.ScreenUtils;

public class ArtistFragment extends BaseGridFragment<ArtistFragment.MyViewHolder, ArtistCard> {


    @Override
    public MyViewHolder createItemViewHolder(ViewGroup parent) {
        View view = layoutInflater.inflate(R.layout.artist_card, parent, false);
        MyViewHolder holder = new MyViewHolder(view, new ArtistListener() {
            @Override
            public void onArtistClick() {

            }
        });
        return holder;
    }

    /**
     * 跳转到用户动态
     */
    public void forwardUserDynamic() {
        Intent intent = new Intent();
        startActivity(intent);
    }

    @Override
    public MyViewHolder createfootViewHolder(View view) {
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public String createReqUrl() {
        return "";
    }

    public int getColNum() {
        return 2;
    }

    protected static class MyViewHolder extends BaseRecycleViewHolder<ArtistCard> {
        /**
         * card 图片
         */
        private ImageView mIvArtistCard;
        /**
         * 用户昵称
         */
        private TextView mTvUserNickName;
        /**
         * 被见证次数
         */
        private TextView mTvKeepWitness;
        private ArtistListener listener;
        /**
         * 坚持天数
         */
        private TextView mTvKeepDays;

        private View view;

        private MyViewHolder(View itemView, ArtistListener listener) {
            this(itemView);
            this.listener = listener;
        }

        public MyViewHolder(View itemView) {
            super(itemView);
            initWidget(itemView);
            this.view = itemView;
        }

        public void initWidget(View view) {
            mIvArtistCard = (ImageView) view.findViewById(R.id.iv_artist_card);
            mTvUserNickName = (TextView) view.findViewById(R.id.tv_user_nickname);
            mTvKeepWitness = (TextView) view.findViewById(R.id.tv_keep_witness);
            mTvKeepDays = (TextView) view.findViewById(R.id.tv_keep_days);
        }

        @Override
        public void renderView(ArtistCard data, int position) {
            Picasso.with(context).load(R.drawable.artist_card_test).into(mIvArtistCard);
        }

        /**
         * 重新设置layout布局
         * @param position positon位置
         */
        public void resetLayout(int position) {
            int firstleftMargin = ScreenUtils.dp2px(10);
            int fristrightMargin = ScreenUtils.dp2px(10);
            int secondLeftMargin = ScreenUtils.dp2px(10);
            int secondRightMargin = ScreenUtils.dp2px(10);
            GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
            if (position % 2 == 0) {
                lp.leftMargin = firstleftMargin;
                lp.rightMargin = fristrightMargin;
                //第一列
            } else {
                lp.leftMargin = secondLeftMargin;
                lp.rightMargin = secondRightMargin;
                //第二列
            }
            view.setLayoutParams(lp);
        }

    }


    private interface ArtistListener {
        void onArtistClick();
    }


}
